package main

import (
	"context"
	"log"
	"minio-demo/client"
	"minio-demo/server"
	"os"
	"path/filepath"
)

func main() {
	// download()
	// upload()
	// makeAccess()
	// log.Printf("file entry: %+v\n", fe)

	server.Run(":8081")
}

const (
	bucketName = "test"
	objectName = "2.PNG"
)

func download() {
	data, err := client.Download(context.Background(), bucketName, objectName)
	if err != nil {
		panic(err)
	}
	fn := "d:\\2.png"
	os.WriteFile(fn, data, 0777)
	log.Printf("download file: %s\n", fn)
}

func makeAccess() {
	// err := client.MakeBucketAccess(context.Background(), bucketName)
	// if err != nil {
	// 	panic(err)
	// }
	// log.Printf("DONE")
	polic, _ := client.GetBucketPolicy(context.Background(), bucketName)
	log.Printf("%s", polic)
}

func createBucket() {
	err := client.CreateBucket(context.TODO(), "test")
	if err != nil {
		panic(err)
	}
	log.Printf("create bucket success.")
}

func upload() {
	file := `C:\Users\Administrator\Pictures\677276.jpg`
	fd, _ := os.ReadFile(file)
	// fn := path.Base(file)
	fn := filepath.Base(file)
	log.Printf("fn %s\n", fn)
	fe := &client.FileEntry{FileName: fn, FileData: fd}
	fi, err := client.UploadReturnUrl(context.Background(), "test", fe)
	if err != nil {
		panic(err)
	}
	log.Printf("fi: %+v\n", fi)
}
